package com.ptszyxx.popose.module.main.user.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ysg.base.BaseViewModel;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.BaseListResponse;
import com.ysg.http.HttpUtils;
import com.ysg.http.callback.OnSuccessListResult;
import com.ysg.http.data.CommonRepository;
import com.ysg.http.data.entity.dynamic.DynamicResult;

import java.util.HashMap;
import java.util.Map;

public class UserDetailDynamicVM extends BaseViewModel<CommonRepository> {
    public String userId;

    public UserDetailDynamicVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onDynamicEvent = new SingleLiveEvent<>();
    }

    public void requestList(boolean refresh){
        if (refresh){
            page = 1;
        }else {
            page++;
        }
        Map<String, String> map = new HashMap<>();
        map.put("pageno", String.valueOf(page));
        map.put("userid", String.valueOf(userId));

        HttpUtils.getInstance()
                .list(model.userDynamicPage(map), this,
                        new OnSuccessListResult<DynamicResult>() {
                            @Override
                            public void onSuccessResult(BaseListResponse<DynamicResult> response) {
                                uc.onDynamicEvent.setValue(response.getData());
                            }
                        });
    }

}
